<template>
	<view class="content">

		<!-- 提问 -->
		<form @submit="formSubmit" class="qusetion">
			<text class="formTitle">请输入心仪对象的臂贴号</text>
			<text class="formTitle2" >（最多输入3个，最少输入1个）</text>
			<view class="items">
				<text>臂贴号一</text>
				<input type="number" name="code" maxlength="3" placeholder="请输入心仪对象的臂贴号 如:001" >
			</view>

			<view class="items">
				<text>臂贴号二</text>
				<input type="number" name="codeTwo" maxlength="3" placeholder="请输入心仪对象的臂贴号 如:001" >
			</view>

			<view class="items">
				<text>臂贴号三</text>
				<input type="number" name="codeThree" maxlength="3" placeholder="请输入心仪对象的臂贴号 如:001" >
			</view>

			<button type="default" form-type="submit">提交</button>
		</form>




	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapState(['token', 'userId'])
		},
		data() {
			return {
				//活动id
				id: '',
			};
		},
		onLoad(data) {
			if (data.scene) {
				this.id = data.scene;
			}
		},
		onShow() {
			console.log('token:' + this.token);
			if (!this.token) {
				uni.showModal({
					title: '您还未登录',
					content: '点击登录,登录后可查看更多!',
					showCancel: true,
					confirmText: '登录',
					success: (res) => {
						// console.log(res);
						if (res.confirm) {
							uni.navigateTo({
								url: "/pages/index/wxLogin"
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}

					}
				});
			}
		},
		methods: {
			//提交问题
			formSubmit(e) {
				let value = e.detail.value;

				if (!value.code.replace(/\s+/g, "") && !value.codeTwo.replace(/\s+/g, "") && !value.codeThree.replace(/\s+/g, "")) {
					uni.showToast({
						title: '至少填入一个号码!',
						icon: 'none',
						mask: true
					});
					return false;
				}
				//执行上传
				console.log(value);
				this.submit(value);

			},
			async submit(e) {
				try {
					let params = {
						token: this.token,
						userId: this.userId,
						activeId: this.id,
						nums: [e.code, e.codeTwo, e.codeThree]
					}
					let res = await this.$request.request.post('/api/wechat/speed', params);
					console.log(res);
					if (res.code == 200) {
						uni.showToast({
							title: res.msg,
							mask: true
						});
					}
				} catch (err) {
					this.$request.error(err, this)
				}
			}
		}
	}
</script>

<style lang="scss">
	@import 'speedDating.scss'
</style>
